package com.sinoglobal.sinostore.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.sinoglobal.sinostore.R;

/**
 * @author czz
 * @createdate 2014-9-11 下午2:20:10
 * @Description: TODO(辣椒圈商城 dilog风格1:大致分为三种风格 在使用时可以查看布局来选择适合自己的dialog)
 */
public class ShopDialogStyle3 extends Dialog implements android.view.View.OnClickListener {

	private TextView phone1,phone2;
	private String phone1Str,phone2Str;
	private Context context;
	public void setCancelable(boolean cancelable) {
		this.setCanceledOnTouchOutside(cancelable);
	}

	public ShopDialogStyle3(Context context,String phone1Str) {
		super(context, R.style.alert_dialog);
		this.context = context;
		setContentView(R.layout.shop_dialogstyle3);
		this.phone1Str = phone1Str;
		init();
		showListener();
		// windowDeploy(0, 0);
		setCanceledOnTouchOutside(true);
		phone1.setText(String.format("拨打    %s", phone1Str));
		phone2.setVisibility(View.GONE);
	}
	public ShopDialogStyle3(Context context,String phone1Str,String phone2Str) {
		super(context, R.style.alert_dialog);
		this.context = context;
		setContentView(R.layout.shop_dialogstyle3);
		this.phone1Str = phone1Str;
		this.phone2Str = phone2Str;
		init();
		showListener();
		// windowDeploy(0, 0);
		setCanceledOnTouchOutside(true);
		phone1.setText(String.format("拨打    %s", phone1Str));
		phone2.setText(String.format("拨打    %s", phone2Str));
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	public void init() {
		phone1 = (TextView) findViewById(R.id.phone1);
		phone2 = (TextView) findViewById(R.id.phone2);
	}

	public void showListener() {
		phone1.setOnClickListener(this);
		phone2.setOnClickListener(this);
	}
	@Override
	public void onClick(View v) {
		cancel();
		Intent intent =null;
		Uri uri = null;
		int id = v.getId();
		if (id == R.id.phone1) {
			uri= Uri.parse("tel:"+phone1Str);
			intent = new Intent(Intent.ACTION_DIAL, uri);
			context.startActivity(intent);
		} else if (id == R.id.phone2) {
			uri = Uri.parse("tel:"+phone2Str);
			intent = new Intent(Intent.ACTION_DIAL, uri);
			context.startActivity(intent);
		} else {
		}
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		try {
			super.show();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}
